<?php
/**
 * @package qBase
 * @subpackage web
 */

/**
 * QWebRequest represents a web request made by a browser to a web server
 * 
 * @package qBase
 * @subpackage web
 */
final class QWebRequest extends QObject 
{
	/**
	 * The list of parameters sent using the GET method
	 *
	 * @var array
	 */
	private $get = array();
	/**
	 * Specifies that this is the default request, the default request will use the default PHP parameters rather than it's own
	 *
	 * @var boolean
	 */
	private $default = false;
	/**
	 * The response that will be sent for this request
	 *
	 * @var QWebResponse
	 */
	private $response;
	
	/**
	 * The constructor
	 *
	 * @param boolean $default Specifies if this is the default request
	 */
	public function __construct($default = false)
	{
		if (!$default)
			throw new Exception("QWebRequest::__construct() only default request is implemented at the moment");
		$this->default = $default;
	}
	
	/**
	 * Gets an element sent using the GET method for the specified key. If no key is specified it returns the entire array
	 *
	 * @param string $key
	 * @return mixed
	 */
	public function get($key = null)
	{
		if ($this->default)
		{
			if ($key)
			{
				if (isset($_GET[$key]))
					return $_GET[$key];
				else 
					return null;
			}
			else 
			{
				return $_GET;
			}
		}
		else 
		{
			
		}
	}
	
	/**
	 * Unsets a key from the GET array
	 *
	 * @param string $key
	 */
	public function unsetGet($key)
	{
		if ($this->default)
			unset( $_GET[$key] );
		else 
			{}
	}
	
	/**
	 * The response associated to the request
	 *
	 * @return QWebResponse
	 */
	public function response()
	{
		return $this->response;
	}
	
	/**
	 * Sets the response associated to the request
	 *
	 * @param QWebResponse $response
	 */
	public function setResponse(QWebResponse $response)
	{
		$this->response = $response;
	}
	
	/**
	 * Gets an element sent using the POST method for the specified key. If no key is specified it returns the entire array
	 *
	 * @param string $key
	 * @return mixed
	 */
	public function post($key = null)
	{
		if ($this->default)
		{
			if ($key)
			{
				if (isset($_POST[$key]))
					return $_POST[$key];
				else 
					return null;
			}
			else 
				return $_POST;
		}
		else 
		{
			
		}
	}
}

?>